<!-- 导航菜单栏 -->
<template>
<div class="sidebar-wp">
  <div class="top" @click="isShow ? setHide() : setShow()">导航栏</div>
  <template v-if="isBlock">
    <div class="list-box" :class="{show: isShow}">
      <ul>
        <template v-for="(item, index) in routes">
          <li v-if="item.meta">
            <router-link :to="item.path">{{item.meta.title}}</router-link>
          </li>
        </template>
      </ul>
    </div>
  </template>
</div>
</template>
<script>
export default {
  name: 'sidebar',
  data () {
    return {
      isBlock: false,
      isShow: false,

      // 获取router列表
      routes: require('@/router').routes,
    }
  },
  watch: {
    '$route.path' (val) {
      this.setHide();
    }
  },
  methods: {
    setShow () {
      this.isBlock = true;
      setTimeout(() => {
        this.isShow = true;
      }, 30);
    },
    setHide () {
      this.isShow = false;
      setTimeout(() => {
        this.isBlock = false;
      }, 300);
    }
  }
}
</script>
<style lang="scss" scoped>
.sidebar-wp {
  position: fixed;
  top: 0;
  right: 0;
  width: 250px;
  z-index: 100;

  .top {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 30px;
    cursor: pointer;
    background: rgba(64,158,255,0.1);
    line-height: 30px;
    text-align: center;
    font-size: 16px;
  }

  .list-box {
    position: absolute;
    z-index: 1;
    top: 10vh;
    left: 0;
    right: 0;
    padding: 45px 0 15px;
    height: 100vh;
    background: #fff;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
    box-sizing: border-box;
    opacity: 0;
    transition: all .3s;
    &.show {
      top: 0;
      opacity: 1;
    }
    &:before {
      content: '';
      position: absolute;
      top: -15px;
      left: 0;
      right: 0;
      height: 20px;
      background: #fff;
    }

    ul {
      height: 100%;
      overflow: auto;
    }

    li {
      padding: 5px 20px;
      border-bottom: 1px solid #EBEEF5;
      line-height: 30px;
    }
  }
}
</style>